import { eventHandler, getQuery } from 'h3';
import { verifyAccessToken } from '~/utils/jwt-utils';

export default eventHandler(async (event) => {
  const userinfo = verifyAccessToken(event);
  if (!userinfo) {
    return { code: 401, message: '未授权访问' };
  }

  // 从URL参数中获取requestId
  const { id } = getQuery(event);
  const requestId = Number(id);

  // 模拟数据 - 这里应该从数据库获取，这里用静态数据模拟
  const mockRequest = {
    requestId,
    vehicleId: 1,
    driverId: 1,
    licensePlate: '京A12345',
    driverName: '张三',
    requestType: '维修',
    description: '车辆发动机异响，需要检查',
    imageUrls: [
      'https://picsum.photos/400/300?random=1',
      'https://picsum.photos/400/300?random=2',
    ],
    requestTime: '2024-01-15T10:30:00.000Z',
    approvalStatus: '待审批',
  };

  return {
    code: 200,
    data: mockRequest,
    message: '获取申请详情成功',
  };
});
